﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace PSE.Deployment.SetupBase.Configuration
{
    [Serializable]
    public class XmlFile
    {
        [XmlAttribute()]
        public string Title { get; set; }
        [XmlAttribute()]
        public string Description { get; set; }
        public FolderInfo Folder { get; set; }
        public List<XmlTag> Tags { get; set; }

        public XmlFile()
        {
            Tags = new List<XmlTag>();
        }

        public bool HasAnyVisibleTag
        {
            get
            {
                bool hasAtLeastOneVisibleTag = false;

                if (Tags != null && Tags.Count > 0)
                {
                    foreach (XmlTag tag in Tags)
                    {
                        if (tag.IsVisible)
                        {
                            hasAtLeastOneVisibleTag = true;
                            break;
                        }
                    }
                }

                return hasAtLeastOneVisibleTag;
            }
        }

        public bool HasAnyPropertyChanged
        {
            get
            {
                bool hasAtLeastOnePropertyChanged = false;

                if (Tags != null && Tags.Count > 0)
                {
                    foreach (XmlTag tag in Tags)
                    {
                        if (tag.HasChanges || tag.HasAnyPropertyChanged)
                        {
                            hasAtLeastOnePropertyChanged = true;
                            break;
                        }
                    }
                }

                return hasAtLeastOnePropertyChanged;
            }
            set 
            {
                if (Tags != null && Tags.Count > 0)
                {
                    foreach (XmlTag tag in Tags)
                    {
                        tag.HasChanges = value;
                        tag.HasAnyPropertyChanged = value;
                    }
                }
            }
        }
    }
}